package com.yanqu.road.server.cmd.activity.bulletscreen;

import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.pb.activity.BulletScreenProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.activity.bulletscreen.CrossActivityBarrageMessage;
import com.yanqu.road.server.manager.activity.bulletscreen.CrossActivityBulletScreenMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.C_CROSS_ACTIVITY_BULLET_SCREEN_COMMENTS, desc = "弹幕")
public class CrossAddBulletScreenCmd extends CrossCommand {

    int activityId;
    String content;
    String nickName;
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        BulletScreenProto.CrossBulletScreenContentReqMsg launchMsg = BulletScreenProto.CrossBulletScreenContentReqMsg.parseFrom(packet.getBytes());
        activityId = launchMsg.getActivityId();
        content = launchMsg.getContent();
        nickName = launchMsg.getNickName();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        CrossActivityBarrageMessage barrageMessage = CrossActivityBulletScreenMgr.addBarrageMessage(activityId, content, packet.getPlayerId(), nickName, serverId);
        BulletScreenProto.CrossBulletScreenContentRespMsg.Builder respMsg = BulletScreenProto.CrossBulletScreenContentRespMsg.newBuilder();
        respMsg.setActivityId(activityId);
        if(barrageMessage == null){
            respMsg.setRet(1);
        }else{
            respMsg.setMsg(CrossActivityBulletScreenMgr.parseBarrageMessageBuilder(barrageMessage, content, activityId, serverId));
            respMsg.setRet(0);
        }
        MessageHelper.sendPacket(serverId, packet.getPlayerId(), YanQuMessageUtils.buildMessage(Protocol.S_ACTIVITY_BULLET_SCREEN_COMMENTS_FROM_CROSS, respMsg));
    }

    @Override
    public void sendData() {

    }
}
